package com.moxiao.yfjh.module.activity.dal.mysql.merchantInfo;

import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.module.activity.dal.dataobject.merchantInfo.MerchantInfoDO;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.activity.controller.admin.merchantInfo.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 相亲商家信息 Mapper
 *
 * @author mx
 */
@Mapper
public interface MerchantInfoMapper extends BaseMapperX<MerchantInfoDO> {

    default PageResult<MerchantInfoDO> selectPage(MerchantInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MerchantInfoDO>()
                .eqIfPresent(MerchantInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(MerchantInfoDO::getName, reqVO.getName())
                .eqIfPresent(MerchantInfoDO::getMerchantType, reqVO.getMerchantType())
                .eqIfPresent(MerchantInfoDO::getAddress, reqVO.getAddress())
                .eqIfPresent(MerchantInfoDO::getMerchantIntro, reqVO.getMerchantIntro())
                .eqIfPresent(MerchantInfoDO::getMerchantCover, reqVO.getMerchantCover())
                .eqIfPresent(MerchantInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MerchantInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MerchantInfoDO::getId));
    }

    default List<MerchantInfoDO> selectList(MerchantInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MerchantInfoDO>()
                .eqIfPresent(MerchantInfoDO::getNo, reqVO.getNo())
                .likeIfPresent(MerchantInfoDO::getName, reqVO.getName())
                .eqIfPresent(MerchantInfoDO::getMerchantType, reqVO.getMerchantType())
                .eqIfPresent(MerchantInfoDO::getAddress, reqVO.getAddress())
                .eqIfPresent(MerchantInfoDO::getMerchantIntro, reqVO.getMerchantIntro())
                .eqIfPresent(MerchantInfoDO::getMerchantCover, reqVO.getMerchantCover())
                .eqIfPresent(MerchantInfoDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MerchantInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MerchantInfoDO::getId));
    }

    @Select("select count(*) num from blind_merchant_info where no = #{merchantInfoNo}")
    Integer getMerchantInfoNo(@Param("merchantInfoNo") String merchantInfoNo);
}
